﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsumeAndProduceFactory
{
    public interface IConsumeAndProduceFactory
    {
        /// <summary>
        /// 最大生产者数量
        /// </summary>
        int MaxProducers
        {
            get;
            set;
        }

        /// <summary>
        /// 最大消费者数量
        /// </summary>
        int MaxConsumers
        {
            get;
            set;
        }

        /// <summary>
        /// 产品缓冲上限
        /// </summary>
        int MaxProducts
        {
            get;
            set;
        }

        /// <summary>
        /// 工厂开始运作
        /// <returns>
        ///     正常返回0
        ///     没有生产者，返回-1
        ///     没有消费者，返回-2
        ///     两者皆无，返回-3
        /// </returns>
        /// </summary>
        int startwork();

        /// <summary>
        /// 暂停
        /// </summary>
        void pausework();

        /// <summary>
        /// 停止: 将当前的produce线程做完；由consumer清空仓库
        /// </summary>
        void stopwork();

        /// <summary>
        /// 从暂停位置恢复
        /// </summary>
        void resumework();

        /// <summary>
        /// 立刻终止所有线程
        /// </summary>
        void stopImmediately();


        /// <summary>
        /// 生产事件，需要注册方可使用
        /// </summary>
        event FactoryEventHandler Producing;

        /// <summary>
        /// 消费事件，需要注册方可使用
        /// </summary>
        event FactoryEventHandler Consuming;
    }

    public class FactoryEventArgs : EventArgs 
    {
        public FactoryEventArgs(List<Object> products, FactoryMsg msg) 
        {
            this.Products = products;
            this.Msg = msg;
        }

        public FactoryEventArgs(List<Object> products)
        {
            this.Products = products;
        }
        public List<Object> Products;
        public FactoryMsg Msg;
    }

    // 还有什么抽象信息需要传递的？
    public enum FactoryMsg 
    {
        ProducingOk,
        ProducingFinished,
        ProducingWithError,
        ConsumingOK,
        ConsumingFinished, 
        ConsumingWithError
    };  

    public delegate void  FactoryEventHandler(object sender, FactoryEventArgs e);
}
